package main

import (
	"fmt"

	"gitee.com/wuzp__dev/crawler/tree"
)

type myTreeNode struct {
	node *tree.TreeNode
}

func (myNode *myTreeNode) postOrder() {
	if myNode == nil || myNode.node == nil {
		return
	}

	left := myTreeNode{myNode.node.Left}
	left.postOrder()
	right := myTreeNode{myNode.node.Right}
	right.postOrder()
	myNode.node.Print()
}

func main() {
	var root tree.TreeNode

	root = tree.TreeNode{Value: 3}
	root.Left = &tree.TreeNode{}
	root.Right = &tree.TreeNode{5, nil, nil}
	root.Right.Left = new(tree.TreeNode)
	root.Left.Right = tree.CreateNode(2)

	root.Traverse()

	nodeCount := 0
	root.TraverseFunc(func(node *tree.TreeNode) {
		nodeCount++
	})
	fmt.Println(nodeCount)

	c := root.TraverseWithChannel()
	maxNode := 0
	for node := range c {
		if node.Value > maxNode {
			maxNode = node.Value
		}
	}
	fmt.Println("Max node value:", maxNode)

	/*
		nodes := []tree.TreeNode{
			{Value: 3},
			{},
			{6, nil, &root},
		}
		fmt.Println(nodes)

		// root.print()
		root.Right.Left.SetValue(4)
		root.Right.Left.Print()
		fmt.Println()

		root.Print()
		root.SetValue(100)

		var pRoot *tree.TreeNode
		pRoot.SetValue(300)

		pRoot = &root
		pRoot.Print()
		pRoot.SetValue(200)
		pRoot.Print()

		fmt.Println()
		myTreeRoot := myTreeNode{&root}
		myTreeRoot.postOrder()
	*/
}
